package com.cn.utils;

import com.cn.pojo.Orders;
import org.junit.jupiter.api.Order;
import org.springframework.util.RouteMatcher;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 功能描述: <br>
 *
 * @program: wx-nimi-bank
 * @description: 地址工具类
 * @author: Mr.TYJ
 * @create: 2022-06-23 07:51
 **/
public  class  AddressUtil {
    public static List<Map<String,String>> addressResolution(String address){
        Orders orders=new Orders();
        String regex  = "(?<addressProvince>[^省]+省|.+自治区|[^澳门]+澳门|[^香港]+香港|[^市]+市)?(?<addressCity>[^自治州]+自治州|[^特别行政区]+特别行政区|[^市]+市|.*?地区|.*?行政单位|.+盟|市辖区|[^县]+县)(?<addressTown>[^县]+县|[^市]+市|[^镇]+镇|[^区]+区|[^乡]+乡|.+场|.+旗|.+海域|.+岛)?(?<detailAddress>.*)";
        Matcher m= Pattern.compile(regex).matcher(address);
        List<Map<String,String>> table=new ArrayList<Map<String,String>>();
        Map<String,String> row=null;
        while(m.find()){
            row=new LinkedHashMap<String,String>();
            orders.setAddressProvince(m.group("addressProvince"));
            row.put("addressProvince", orders.getAddressProvince()==null?"":orders.getAddressProvince().trim());
            orders.setAddressCity(m.group("addressCity"));
            row.put("addressCity", orders.getAddressCity()==null?"":orders.getAddressCity().trim());
            orders.setAddressTown(m.group("addressTown"));
            row.put("addressTown", orders.getAddressTown()==null?"":orders.getAddressTown().trim());
            orders.setDetailAddress(m.group("detailAddress"));
            row.put("detailAddress", orders.getDetailAddress()==null?"":orders.getDetailAddress().trim());
            table.add(row);
            System.out.println(table.toString());
        }
        return table;
    }

}
